package com.ars.administrators;

import com.ars.db.DBTools;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;

import javax.swing.*;

public class AddAdministratorsController {
    DBTools p;
    @FXML
    private TextField tfAdministratorsName;
    @FXML
    private TextField tfPassword;
    private String administratorsName;
    private String password;

    @FXML
    public void addButtonAction() {
        administratorsName = tfAdministratorsName.getText().trim();
        password = tfPassword.getText().trim();
        if (!administratorsName.equals("") && !password.equals("")) {
            p = new DBTools();
            String sql = "insert into website values(NULL,'" + administratorsName + "','" + password + "',NULL,NULL,'2')";
            int t = p.update(sql);
            if (t != 0) {
                JOptionPane.showMessageDialog(null, "添加成功！");
            } else {
                JOptionPane.showMessageDialog(null, "添加失败！");
            }

        } else {
            JOptionPane.showMessageDialog(null, "表单不能为空，请输入！");
        }
    }

    @FXML
    public void cancelButtonAction() {
        tfAdministratorsName.clear();
        tfPassword.clear();
    }
}
